package com.df.happylearn.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import com.df.happylearn.R;

public class SplashActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        findViewById(R.id.background).startAnimation(createBackgroundAnim());
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_splash;
    }

    private Animation createBackgroundAnim() {
        final ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 1.05f, 1.0f, 1.05f
                , Animation.RELATIVE_TO_SELF, 0.5F, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnim.setFillAfter(true);
        scaleAnim.setDuration(1500);
        scaleAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                startActivity();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        return scaleAnim;
    }

    private void startActivity() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}
